package com.xwq.smartgelleryhub.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xwq.smartgelleryhub.api.aliyunTextToImage.model.CreateTextToImageTaskRequest;
import com.xwq.smartgelleryhub.api.aliyunTextToImage.model.CreateTextToImageTaskResponse;
import com.xwq.smartgelleryhub.api.aliyunaiImageOutPaining.model.CreateOutPaintingTaskResponse;
import com.xwq.smartgelleryhub.api.aliyunaiReshapingImage.model.CreateImageRestyleTaskRequest;
import com.xwq.smartgelleryhub.api.aliyunaiReshapingImage.model.CreateImageRestyleTaskResponse;
import com.xwq.smartgelleryhub.model.dto.picture.*;
import com.xwq.smartgelleryhub.model.entity.Picture;
import com.xwq.smartgelleryhub.model.entity.User;
import com.xwq.smartgelleryhub.model.vo.PictureVO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author XWQ
 * &#064;description  针对表【picture(图片)】的数据库操作Service
 * &#064;createDate  2025-03-10 20:52:24
 */
public interface PictureService extends IService<Picture> {

    /**
     * 图片数据校验
     *
     * @param picture 图片
     */
    void validPicture(Picture picture);

    /**
     * 上传图片
     *
     * @param inputResouce         文件
     * @param pictureUploadRequest 文件上传请求
     * @param loginUser            登录用户
     * @return 图片封装类
     */
    PictureVO uploadPicture(Object inputResouce,
                            PictureUploadRequest pictureUploadRequest,
                            User loginUser);


    /**
     * 获取图片查询条件
     *
     * @param pictureQueryRequest 图片查询条件
     * @return 查询条件
     */
    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);


    /**
     * 返回图片封装类
     *
     * @param picture 图片实体
     * @param request http请求
     * @return 图片封装类
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    /**
     * 返回图片封装类（分页）
     *
     * @param picturePage 分页对象
     * @param request     http请求
     * @return 分页图片包装类
     */
    Page<PictureVO> getPictureVOPage(Page<Picture> picturePage, HttpServletRequest request);

    /**
     * 图片审核
     *
     * @param pictureReviewRequest
     * @param loginUser
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, User loginUser);

    /**
     * 填充审核信息
     *
     * @param picture
     * @param loginUser
     */
    void fillReviewParams(Picture picture, User loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest
     * @param loginUser
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(
            PictureUploadByBatchRequest pictureUploadByBatchRequest,
            User loginUser
    );

    /**
     * 更新图片（管理员）
     *
     * @param pictureUpdateRequest
     * @param request
     * @return
     */
    Boolean updatePicture(PictureUpdateRequest pictureUpdateRequest, HttpServletRequest request);

    /**
     * 清理文件
     *
     * @param oldPicture
     */
    @Async
    void clearPictureFile(Picture oldPicture);

    /**
     * 检查图片的权限
     *
     * @param loginUser
     * @param picture
     */
    void checkPictureAuth(User loginUser, Picture picture);

    /**
     * 删除图片
     *
     * @param pictureId
     * @param loginUser
     */
    void deletePicture(long pictureId, User loginUser);

    /**
     * 编辑图片
     *
     * @param pictureEditRequest
     * @param loginUser
     */
    void editPicture(PictureEditRequest pictureEditRequest, User loginUser);

    /**
     * 根据颜色查询图片
     * @param spaceId
     * @param picColor
     * @param loginUser
     * @return
     */
    List<PictureVO> searchPictureByColor(Long spaceId, String picColor, User loginUser);

    /**
     * 根据颜色查询图片
     * @return
     */
    List<PictureVO> searchAllPictureByColor(String picColor);

    /**
     * 批量修改图片
     * @param pictureEditByBatchRequest
     * @param loginUser
     */
    @Transactional(rollbackFor = Exception.class)
    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, User loginUser);

    /**
     * ai扩图
     * @param createPictureOutPaintingTaskRequest
     * @param loginUser
     * @return
     */
    CreateOutPaintingTaskResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);

    /**
     * ai文字生成图片
     * @param
     * @param loginUser
     * @return
     */
    CreateTextToImageTaskResponse createTextToImageTask(CreatePictureTextToImageTaskRequest createPictureTextToImageTaskRequest, User loginUser);

    /**
     * ai 人像风格重塑
     * @param
     * @param
     * @return
     */
    CreateImageRestyleTaskResponse createImageRestyleTask(PortraitStyleRemakeRequest portraitStyleRemakeRequest, User loginUser);
}
